package ModelLayer;

import java.util.ArrayList;
/**
 * Write a description of class Customer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Customer extends Person
{
    private int customerId;
    private double discount;
    private ArrayList<Sale> sales;

    public Customer(int customerId, String name, String address, String city, String postCode, String eMail)
    {
        super(name,address,city,postCode,eMail);
        this.customerId = customerId;
        discount=0;
        sales = new ArrayList<Sale>();
    }

    public void setCustomerId(int newId)
    {
        customerId = newId;
    }

    /*
     * The discount must be between 1 and 100
     */
    public boolean setDiscount(double newDiscount)
    {
        if(newDiscount>=0 && newDiscount<=100)
        {
            discount = newDiscount;
            return true;
        }
        else
        {
            return false;
        }
    }

    public int getCustomerId()
    {
        return customerId;
    }

    public double getDiscount()
    {
        return discount;
    }

    public double calculateDiscount()
    {
        double realSum = 1 - (getDiscount()/100); //realSum will be used to calculate the sum that the customer has to pay 
        return realSum;
    }

    public void addSale (Sale s)
    {
        sales.add(s);
    }

    public ArrayList<Sale> getSales()
    {
        return sales;
    }

    public double calculateTotalPriceFromAllSales()
    {
        double totalPrice = 0;
        for(int i=0; i<sales.size(); i++)
        {
            totalPrice+= sales.get(i).getTotalPrice();
        }

        return totalPrice;
    }   
}
